package com.bx.implatform.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bx.implatform.entity.User;
import com.bx.implatform.result.Result;
import com.bx.implatform.result.ResultUtils;
import com.bx.implatform.service.FriendService;
import com.bx.implatform.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * desc
 *
 * @author cjq
 * @date 2025/5/22
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api")
public class ApiController {

    private final UserService userService;

    private final FriendService friendService;

    @GetMapping("/addFriends")
    public Result addFriends() {

        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        List<User> userList =  userService.list(queryWrapper);
        int count = userList.size();
        for(int i=0;i<count;i++) {
            User user1 = userList.get(i);
            for(int j=i+1;j<count;j++) {
                User user2 = userList.get(j);
                if(user1.getId().equals(user2.getId())) {
                    continue;
                }
                friendService.bindFriend(user1.getId(), user2.getId());
                friendService.bindFriend(user2.getId(),user1.getId());
            }
        }

        return ResultUtils.success();
    }

}
